package cn.itcast.web.servlet;

import cn.itcast.daomain.classification;
import cn.itcast.service.RouteService;
import cn.itcast.service.impl.RouteServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/classIfcationServlet")
public class classIfcationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session=request.getSession();

        RouteService service=new RouteServiceImpl();
        List<classification> classifications=service.classifications();
        ObjectMapper mapper=new ObjectMapper();
        String json=mapper.writeValueAsString(classifications);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().append(json);
    }
}
